﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SalaDeEnsayo.ApplicationService.Model.Entity;

namespace SalaDeEnsayo.ApplicationService.Model
{
    public class RolService : BaseService
    {
        public List<Rol> ListarRolesPorUsuario(long usuarioId)
        {
            List<Rol> listaUsuarios = new List<Rol>();
            using (var dr = this.SalaDeEnsayoDB.ExecuteReader("RolesPorUsuarioListar", usuarioId))
            {
                while (dr.Read())
                {
                    listaUsuarios.Add(GetEntity(dr));
                }
            }
            return listaUsuarios;
        }

        private Rol GetEntity(System.Data.IDataReader dr)
        {
            return new Rol(dr["Id"] is System.DBNull ? 0 : (long)dr["Id"],
                           dr["Nombre"] is System.DBNull ? string.Empty : (string)dr["Nombre"]);
        }
    }
}
